#ifndef PUBLICTRANSPORTTILEREQUEST_H_
#define PUBLICTRANSPORTTILEREQUEST_H_

#include <e32base.h>
#include <http\RHTTPTransaction.h>
#include <http\RHTTPSession.h>
#include <http\MHTTPTransactionCallback.h>
#include <http\MHTTPDataSupplier.h>
#include <es_sock.h>


class CPublicTransportTileRequest;

struct MPublicTransportTileCallback
	{
	virtual void MPublicTransportTileCallbackRunL(CPublicTransportTileRequest* aTileRequest, TInt aZoom, TInt aTileX, TInt aTileY, TInt aStatus, TInt aLastError, TInt aStatusCode, const TDesC8& aData, void* iUserData) = 0;
	virtual TInt MPublicTransportTileCallbackRunError(CPublicTransportTileRequest* aTileRequest, TInt aZoom, TInt aTileX, TInt aTileY, TInt aError, const TDesC8& aData, void* iUserData) = 0;
	virtual ~MPublicTransportTileCallback();
	};

class CPublicTransportTileSession : public CBase
	{
	
RArray<CPublicTransportTileRequest*> iRequests;
friend class CPublicTransportTileRequest;
public:
	// constructors and destructor
	CPublicTransportTileSession();
	static CPublicTransportTileSession* NewL();
	static CPublicTransportTileSession* NewLC();        
	void ConstructL();
	virtual ~CPublicTransportTileSession();
	RHTTPSession iHTTPSession;
	void SetConnectionInfoL(const RConnection& aConnection, const RSocketServ& aSocketServ);
	void CloseConnectionL();
	void NotifyConnected();
	};


class CPublicTransportTileRequest : public CBase, public MHTTPTransactionCallback
	{
private:
	TInt iZoom, iTileX, iTileY;
	RBuf8 iBody;
	MPublicTransportTileCallback* iTarget;
	void* iUserData;
	RHTTPTransaction iTransaction;
	CPublicTransportTileSession* iSession;
	void ConstructL(CPublicTransportTileSession* aSession);
	
	TInt iLastError;
	
public:
    virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
    virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
	void SubmitL(TInt aZoom, TInt aTileX, TInt aTileY, MPublicTransportTileCallback* aTarget, void* aUserData = NULL);
	void Cancel();
	static CPublicTransportTileRequest* NewLC(CPublicTransportTileSession* aSession);
	static CPublicTransportTileRequest* NewL(CPublicTransportTileSession* aSession);
	virtual ~CPublicTransportTileRequest();
	};

#endif /* PUBLICTRANSPORTTILEREQUEST_H_ */
